﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;

namespace jQXBdempWCF.WebApp
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Customer
    {

        [OperationContract]
        [WebGet(ResponseFormat=WebMessageFormat.Json)]
        public List<jQXBM.WCF.Models.Customer> getCustomerList()
        {
            List<jQXBM.WCF.Models.Customer> customerList = new List<jQXBM.WCF.Models.Customer>();
            for (int idx = 0; idx < 10; idx++)
            {
                jQXBM.WCF.Models.Customer customer = new jQXBM.WCF.Models.Customer();
                customer.id = idx;
                customer.Name = "CustomerName" + idx.ToString();
                customer.Surname = "CustomerSurname" + idx.ToString();
                customer.Address = "CustomerStreet" + idx.ToString();
                customer.ordersList = new List<jQXBM.WCF.Models.Order>();
                customerList.Add(customer);
            }
            return customerList;
        }

        [OperationContract]
        [WebGet(ResponseFormat = WebMessageFormat.Json)]
        public jQXBM.WCF.Models.Customer getCustomer(int id)
        {
            jQXBM.WCF.Models.Customer customer = new jQXBM.WCF.Models.Customer();
            customer.id = id;
            customer.Name = "CustomerName" + id.ToString();
            customer.Surname = "CustomerSurname" + id.ToString();
            customer.Address = "CustomerStreet" + id.ToString();
            customer.ordersList = new List<jQXBM.WCF.Models.Order>();
            for (int i = 0; i < 5; i++)
            {
                customer.ordersList.Add(new jQXBM.WCF.Models.Order() { date = DateTime.Now.ToShortDateString(), number =  Guid.NewGuid().ToString() });
            }
            return customer;
        }

        [OperationContract]
        public jQXBM.WCF.Models.Customer SaveCustomer(jQXBM.WCF.Models.Customer customer)
        {

            customer.Name += "Just Saved";
            return customer;
        }
       
    }
}
